package com.sky.controller.user;

import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.Result;
import com.sky.service.user.UserOrderService;
import com.sky.vo.OrderSubmitVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
@Slf4j
@RestController
@RequestMapping("/user/order")
@Api(tags = "C端-订单相关接口")
public class OrderController {
    @Autowired
    private UserOrderService userOrderService;

    /**
     * 订单预计送达时间
     * @param customerAddress
     * @param shopId
     * @return
     */
    @GetMapping("/getEstimatedDeliveryTime")
    public Result getEstimatedDeliveryTime(String customerAddress ,Long shopId){
        LocalDateTime estimatedDeliveryTime =userOrderService.getEstimatedDeliveryTime(customerAddress,shopId);
        return Result.success(estimatedDeliveryTime);
    }
    /**
     * 订单提交
     */
    @PostMapping("/submit")
    @ApiOperation("订单提交")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        log.info("controller层，订单提交：{}",ordersSubmitDTO);
        OrderSubmitVO result=userOrderService.submit(ordersSubmitDTO);
        return Result.success(result);
    }
}
